<template>
	<view class="course_list_container">
		<view class="item" v-for="(item, index) in courseList" :key='index'
			@click="goNav('/me/create/course/edit?courseId='+item.courseId)">
			<view class="pic_title align-center">
				<image :src='item.titleImg' mode="aspectFill"></image>
				<view class="title_box" style="position: relative;flex: 1;">

					<image src='/static/images/index/v_3.png'
						style="width: 28rpx;height: 28rpx;position: absolute;right: 0;top: 0;"
						@click.stop="deleteItem(item.courseId,index)"></image>

					<view class="name">{{item.title}}</view>
					<view style="display: flex; align-items: center;">
						<view class="type">{{item.classificationName}}</view>
						<!-- <view class="label_text text-ellipsis one-text-ellipsis" style="flex: 1;">{{item.courseLabel}}
						</view> -->
						<view v-for='(item1, index1) in item.courseLabel' :key='index1' v-if="index1 < 3"
							style="height: 36rpx;border-radius: 10rpx;border: 1px solid #3D86F4;padding: 0 10rpx;font-weight: bold;font-size: 20rpx;color: #3D86F4;margin-left: 10rpx;">
							#{{item1}}</view>
					</view>
					<view class="label">是否收费：<text style="color: #333333;">{{item.isPrice==1?'是':'免费'}}</text></view>
					<view class="label">购买剧价格：<text style="color: #FC7885;">{{item.price}}</text></view>
					<view style="display: flex;" class="play_btn_box">
						<view @click.stop="goNav('/me/create/video/index?courseId='+item.courseId)">
							<image src='/static/images/index/v_1.png'></image>
							<text>视频</text>
						</view>
						<view @click.stop="$navTo('/me/order/index')">
							<image src='/static/images/index/v_2.png'></image>
							<text>平台推广</text>
						</view>
					</view>
				</view>
			</view>
			<!-- <view class="btn_box">
				<u-button type="error" size="mini" @click="$navTo('/me/order/index')">平台推广</u-button>
				<u-button type="error" size="mini" @click="deleteItem(item.courseId,index)">删除</u-button>
				<u-button type="primary" size="mini"
					@click.stop="goNav('/me/create/course/edit?courseId='+item.courseId)">修改</u-button>
				<u-button type="success" size="mini"
					@click.stop="goNav('/me/create/video/index?courseId='+item.courseId)">视频</u-button>

			</view> -->
		</view>

		<u-loadmore v-if="courseList.length > 0" :status="status" />
		<empty title="暂无资源" :isShow='false' v-if="courseList.length==0"></empty>
	</view>
</template>

<script>
	import empty from '@/components/empty.vue'
	export default {
		components: {
			empty
		},
		data() {
			return {
				courseList: [],
				status: 'loadmore',
				page: 1,
				limit: 10,
			}
		},
		onLoad() {
			this.getCourseList()
		},
		onShow() {


		},
		methods: {

			deleteItem(id, index) {
				var that = this
				uni.showModal({
					title: '提示',
					content: '是否确认删除该资源',
					success: function(res) {
						if (res.confirm) {
							that.$u.get("/app/user/updateDeleteByApp?id=" + id).then(
								res => {
									if (res.code === 0) {
										that.courseList.splice(index, 1)
										uni.showToast({
											title: '删除成功',
											icon: "none"
										})
									} else if (res.code === -1) {
										uni.showModal({
											title: '温馨提示',
											content: res.msg,
											cancelText: "取消", // 取消按钮的文字  
											confirmText: "去商城", // 确认按钮的文字 
											confirmColor: '#8B8FF0',
											success: e => {
												if (e.confirm) {
													uni.navigateTo({
														url: '/me/shop/index'
													});
												}
											}
										});

									} else {
										uni.showToast({
											title: res.msg,
											icon: "none",
											duration: 5000
										})
									}
								});


						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			getCourseList() {

				let data = {
					limit: this.limit,
					page: this.page
				}

				this.$u.get("/app/user/selectCourseByApp", data).then(
					res => {
						if (res.code === 0) {
							this.pages = res.data.totalPage
							if (this.page < this.pages) {
								this.status = 'loadmore'
							} else {
								this.status = 'nomore'
							}
							for (var i in res.data.list) {
								res.data.list[i].courseLabel = res.data.list[i].courseLabel.split(',')
							}
							//courseLabel
							if (this.page == 1) {
								this.courseList = res.data.list
							} else {
								this.courseList = [...this.courseList, ...res.data.list]
							}
						} else {
							uni.stopPullDownRefresh();
						}
					});


			},
			goNav(e) {
				uni.navigateTo({
					url: e
				})
			},
		},
		onReachBottom: function() {
			if (this.page < this.pages) {
				this.page += 1
				this.status = 'loading'
				this.getCourseList()

			} else {
				this.status = 'nomore'
			}

		},
		onPullDownRefresh: function() {
			this.page = 1;
			this.getCourseList()
		},

	}
</script>

<style scoped lang="scss">
	.play_btn_box {
		margin-top: 12rpx;

		image {
			width: 20rpx !important;
			height: 20rpx !important;
			margin-right: 8rpx !important;
			border-radius: 0 !important;
		}

		view {
			display: flex;
			align-items: center;
			justify-content: center;

			&:nth-child(1) {
				width: 140rpx;
				height: 56rpx;
				background: #373A44;
				border-radius: 10rpx;
				margin-right: 10rpx;
			}

			&:nth-child(2) {
				width: 180rpx;
				height: 56rpx;
				background: #FB3159;
				border-radius: 10rpx;
			}

			text {
				font-weight: 500;
				font-size: 20rpx;
				color: #FFFFFF;
			}
		}
	}


	.course_list_container {
		padding: 20rpx 30rpx;

		.item {
			background: #FFFFFF;
			border-radius: 10rpx;
			padding: 30rpx 20rpx;
			margin-bottom: 20rpx;

			.pic_title {
				display: flex;

				image {
					width: 200rpx;
					height: 240rpx;
					border-radius: 8rpx;
					margin-right: 16rpx;
					flex-shrink: 0;
				}

				.name {
					display: block;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
					width: 400rpx;
					font-weight: bold;
					font-size: 28rpx;
					color: #1A1A1A;
					padding-bottom: 16rpx;
				}

				.label {
					font-weight: 500;
					font-size: 24rpx;
					color: #999999;
					padding-top: 10rpx;

					text {
						font-weight: bold;
						font-size: 24rpx;
					}
				}

				.type {
					height: 36rpx;
					background: #FAEAEC;
					border-radius: 10rpx;
					font-weight: bold;
					font-size: 20rpx;
					color: #FD7885;
					padding: 0 16rpx;
					line-height: 36rpx;
				}

				.label_text {
					font-weight: 400;
					font-size: 28rpx;
					color: #969696;
					// display:block;
					// white-space:nowrap;
					// overflow:hidden;
					// text-overflow:ellipsis;
					// width: 500rpx;
				}
			}

			.btn_box {
				display: flex;
				margin-top: 20rpx;
				justify-content: flex-end;

				button {
					margin: 0 !important;
					margin-left: 20rpx !important;
				}
			}
		}
	}
</style>